using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class ProductsNonePaging : System.Web.UI.Page
{
    private string  strConn;
    public ProductsNonePaging()
    {
        strConn = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
    }

    private void LoadData()
    {
        // buoc 1. tao doi tuong ket noi
        SqlConnection conn = new SqlConnection(strConn);

        // buoc 2. tao doi tuong dataApapter de thuc thi cau lenh truy van
        SqlDataAdapter adapter = new SqlDataAdapter("select * from Products", conn);
        // buoc 3. tao doi tuong dataset de luu ket qua cau truy van
        DataSet ds = new DataSet();
        // buoc 4. goi hamn fill de thuc thi cau lenh truy van va luu ket qua vao DataTable co ten prods o trong
        // dataset ds
        adapter.Fill(ds, "prods");
        // buoc 5. binding du lieu vao GridView grvProducts
        grvProducts.DataSource = ds.Tables["prods"];
        grvProducts.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
    }
   
    protected void grvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvProducts.PageIndex = e.NewPageIndex;
        LoadData();
    }
}
